package myzzyl.controller;



import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.DeviceDto;
import myzzyl.domain.pojo.Device;
import myzzyl.domain.vo.DeviceVo;
import myzzyl.response.BaseResponse;
import myzzyl.response.PageResponse;
import myzzyl.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/device")
@Tag(name = "设备相关")
@Slf4j
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 分页获取设备
     */
    @GetMapping("/pageQueryDevice")
    public BaseResponse<PageResponse<Device>> pageQuery(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(name = "deviceName", required = false) String deviceName,
                                                @RequestParam(name = "productKey", required = false) String productKey,
                                                @RequestParam(name = "locationType", required = false) Integer locationType) {
        log.info("分页获取设备:{}, {}, {}, {}, {}", pageNum, pageSize, deviceName, productKey, locationType);
        PageResponse<Device> response = deviceService.pageQuery(pageNum, pageSize, deviceName, productKey, locationType);
        return BaseResponse.success(response);
    }

    /**
     * 获取设备详情
     */
    @PostMapping("/QueryDeviceDetail")
    public BaseResponse<DeviceVo> getInfo(@RequestBody DeviceDto deviceDto) {
        log.info("获取设备详情:{}", deviceDto);
        return BaseResponse.success(deviceService.getInfo(deviceDto));
    }


    /**
     * 新增设备
     */
    @PostMapping("/RegisterDevice")
    public BaseResponse<Boolean> add(@RequestBody DeviceDto deviceDto) {
        log.info("新增设备:{}", deviceDto);
        return BaseResponse.success(deviceService.add(deviceDto));
    }


    /**
     * 编辑设备
     */
    @PutMapping("/UpdateDevice")
    public BaseResponse<Boolean> edit(@RequestBody DeviceDto deviceDto) {
        log.info("编辑设备:{}", deviceDto);
        return BaseResponse.success(deviceService.edit(deviceDto));
    }

    /**
     * 删除设备
     */
    @DeleteMapping("/DeleteDevice")
    public BaseResponse<Boolean> remove(@RequestBody DeviceDto deviceDto) {
        log.info("删除设备:{}", deviceDto);
        return BaseResponse.success(deviceService.remove(deviceDto));
    }


    /**
     * 查看物模型运行状态卡片
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public BaseResponse<List<DeviceVo>> QueryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        log.info("查看物模型运行状态卡片:{}", deviceDto);
        return BaseResponse.success(deviceService.QueryDevicePropertyStatus(deviceDto));
    }


}
